package com.example.ocridentification.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Base64;

public class ImageToBase64 {
    public static String imageToBase64(String imagePath) throws IOException {
        File file = new File(imagePath);
        byte[] bytes = new byte[(int) file.length()];

        try (FileInputStream fis = new FileInputStream(file)) {
            fis.read(bytes);
        }
        return Base64.getEncoder().encodeToString(bytes);
    }

    public static String imageToBase64(byte[] bytes) throws IOException {
        return Base64.getEncoder().encodeToString(bytes);
    }
}
